<?php
	session_start();
	mysql_connect("localhost", "sapmenet_admin", "a1s2d3f4g5h6j7") or die ("Problem with datebase");
	mysql_select_db("sapmenet_users"); 
	$comments=mysql_query("SELECT comments.ID, concat(users.firstName, ' ', users.lastName) AS fullName, users.mainPic, comments.numberOfLikes, comments.numberOfDislikes, comments.whoLikes, comments.whoDislikes, comments.text FROM comments JOIN users ON comments.userId = users.ID WHERE picID={$_POST['snID']} ORDER BY id desc");                                     
	echo "<div id='comments'>";
	echo"<div id='headerLess'>";
	echo "<div id='commentTextBox'><textarea id='picCommentText' maxlength = '200'></textarea><div class = 'addCommentButton' id='".$_POST['snID']."' title='Add comment'><img src='add-comment.png'></div></div><br><br><br><br>";
	if ($_SESSION['JID']!=$_SESSION['id'])
	{
		while ($result=mysql_fetch_array($comments, MYSQL_NUM))
		{
			echo "<dic id='".$result[0]."' class='wholeComment'><div class='PicOfCommenter'><img src='".$result[2]."mini.jpg'></div><div class='movingCommentsDiv'><div class='nameOfCommenter'><a href=http://sapme.net/Framework/profilePage.php?id=".$_SESSION['JID'].">".$result[1].":</a></div> <div class='textOfComment'>".$result[7]."</div><div id='commentLikes' class = 'userOpinion'> <img src = 'like.png' class = 'likeComment' id = ".$result[0]."> Likes: ".$result[3]."</div> <div id='commentDislikes' class = 'userOpinion'> <img src = 'dislike.png' class = 'dislikeComment' id = ".$result[0]."> Dislikes: ".$result[4]."</div></div><br><br><br><br><br><br><br>";
		}
	}
	else
	{
		while ($result=mysql_fetch_array($comments, MYSQL_NUM))
		{
			echo "<dic id='".$result[0]."' class='wholeComment'><div class='PicOfCommenter'><img src='".$result[2]."mini.jpg'></div><div class='movingCommentsDiv'><div class='nameOfCommenter'><a href=http://sapme.net/Framework/profilePage.php?id=".$_SESSION['JID'].">".$result[1].":</a></div> <div class='pictureCommentDeleteButton' title = 'Delete comment' id=".$result[0]."><img src='icons/close.png'></div><div class='textOfComment'>".$result[7]."</div><div id='commentLikes' class = 'userOpinion'> <img src = 'like.png' class = 'likeComment' id = ".$result[0]."> Likes: ".$result[3]."</div> <div id='commentDislikes' class = 'userOpinion'> <img src = 'dislike.png' class = 'dislikeComment' id = ".$result[0]."> Dislikes: ".$result[4]."</div></div><br><br><br><br><br><br><br>";
		}
	}
	echo "</div></div>";
	echo"<script>
		if(jQuery.browser.opera)
	{
		$('.addCommentButton').css('margin-top', '-62px');
		$('.addCommentButton').css('margin-left', '30px');
	}
	var curId;
	$('.addCommentButton').click(function()
	{
		curId = ".$_POST['snID'].";
		$('.addCommentButton').removeClass('toShow');
		$(this).addClass('toShow');
		var theId = $('.toShow').attr('id');
		var theText = $('#picCommentText').val();
		if(theText != '')
		{
			$.post('addCommentPic.php', {PicID : theId, text : theText}, function(data)
			{
				$('#picCommentText').val('');
				$.post('showComments.php', {snID : curId}, function(data)
				{
					$('#commentsDialog').html(data);
				});
			});
		}
		else
		{
		}
	});
	$('#picCommentText').keypress(function(e)
	{
		if(e.keyCode == 13)
		{
			curId = ".$_POST['snID'].";
			var theId = $('.addCommentButton').attr('id');
			var theText = $('#picCommentText').val();
			if(theText != '')
			{
				$.post('addCommentPic.php', {PicID : theId, text : theText}, function(data)
				{
					$('#picCommentText').val('');
					$.post('showComments.php', {snID : curId}, function(data)
					{
						$('#commentsDialog').html(data);
					});
				});
			}
		}
	});
	$('.dislikeComment').click(function()
	{
		$('.dislikeComment').removeClass('focus');
		$(this).addClass('focus');
		var theId = $('.focus').attr('id');
		$.post('dislikeCommentPic.php', {pubID : theId}, function(data)
		{
			var snimkaId = $('.addCommentButton').attr('id');
			$.post('showComments.php', {snID : snimkaId}, function(data)
			{
				$('#commentsDialog').html(data);
			});
		});
	});
	$('.likeComment').click(function()
	{
		$('.likeComment').removeClass('focus');
		$(this).addClass('focus');
		var theId = $('.focus').attr('id');
		$.post('likeCommentPic.php', {pubID : theId}, function(data)
		{
			var snimkaId = $('.addCommentButton').attr('id');
			$.post('showComments.php', {snID : snimkaId}, function(data)
			{
				$('#commentsDialog').html(data);
			});
		});
	});
	$('.pictureCommentDeleteButton').click(function()
	{
		$('.pictureCommentDeleteButton').removeClass('kokain');
		$(this).addClass('kokain');
		var theId = $('.kokain').attr('id');
		$.post('delPictureComment.php', {commentID : theId}, function()
		{
			var snimkaId = $('.addCommentButton').attr('id');
			$.post('showComments.php', {snID : snimkaId}, function(data)
			{
				$('#commentsDialog').html(data);
			});
		});
	});
	</script>";
?>




































